| Conditions | 1 |
| Paths | 1 |
| Total Lines | 58 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | // Directives |
||
| 18 | Directives.prototype.defineConfirm = function () { |
||
| 19 | const _this = this |
||
| 20 | const DirectiveDefinition = {} |
||
| 21 | |||
| 22 | const clickHandler = function (event, el, binding) { |
||
| 23 | event.preventDefault() |
||
| 24 | event.stopImmediatePropagation() |
||
| 25 | |||
| 26 | let confirmMessage = (function () { |
||
| 27 | if (binding.value && binding.value.message) { |
||
| 28 | return binding.value.message |
||
| 29 | } |
||
| 30 | return typeof binding.value === 'string' ? binding.value : null |
||
| 31 | })() |
||
| 32 | |||
| 33 | let thenCallback = (function () { |
||
| 34 | if (binding.value && binding.value.ok) { |
||
| 35 | return binding.value.ok |
||
| 36 | } else { |
||
| 37 | return () => { |
||
| 38 | // Unbind to allow original event |
||
| 39 | el.removeEventListener('click', el.VuejsDialog.clickHandler, true) |
||
| 40 | // Trigger original event |
||
| 41 | clickNode(el) |
||
| 42 | // Re-bind listener |
||
| 43 | el.addEventListener('click', el.VuejsDialog.clickHandler, true) |
||
| 44 | } |
||
| 45 | } |
||
| 46 | })() |
||
| 47 | |||
| 48 | let catchCallback = (function () { |
||
| 49 | if (binding.value && binding.value.cancel) { |
||
| 50 | return binding.value.cancel |
||
| 51 | } |
||
| 52 | return noop |
||
| 53 | })() |
||
| 54 | |||
| 55 | _this.Vue.dialog.confirm(confirmMessage).then(thenCallback).catch(catchCallback) |
||
| 56 | } |
||
| 57 | |||
| 58 | DirectiveDefinition.bind = (el, binding) => { |
||
| 59 | if (el.VuejsDialog === undefined) { |
||
| 60 | el.VuejsDialog = {} |
||
| 61 | } |
||
| 62 | |||
| 63 | el.VuejsDialog.clickHandler = function clickEventHandler(event) { |
||
| 64 | clickHandler(event, el, binding) |
||
| 65 | } |
||
| 66 | |||
| 67 | el.addEventListener('click', el.VuejsDialog.clickHandler, true) |
||
| 68 | } |
||
| 69 | |||
| 70 | DirectiveDefinition.unbind = (el) => { |
||
| 71 | el.removeEventListener('click', el.VuejsDialog.clickHandler, true) |
||
| 72 | } |
||
| 73 | |||
| 74 | return DirectiveDefinition |
||
| 75 | } |
||
| 76 | |||
| 82 |